package ru.eas.sort;

import java.util.Scanner;

public class MergeSort {

    public static void main(String[] args) {
        String testString = "5\n" +
                "2 3 9 2 9";
        Scanner scanner = new Scanner(testString);

//        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }
        MergeSort mergeSort = new MergeSort();
        mergeSort.sort(array, 0, array.length - 1);
        System.out.print(mergeSort.getInversionCount());
    }

    private long inversionCount = 0;

    private int[] sort(int[] array, int left, int right) {
        if (left >= right ) {
            return new int[] { array[left] };
        }
        int middle = (left + right) / 2;
        int[] leftSorted = sort(array, left, middle);
        int[] rightSorted = sort(array, middle + 1, right);
        return merge(leftSorted, rightSorted);
    }

    private int[] merge(int[] leftSorted, int[] rightSorted) {
        int leftLength = leftSorted.length;
        int rightLength = rightSorted.length;
        int[] result = new int[leftLength + rightLength];
        int l = 0;
        int r = 0;
        int i = 0;
        while (i < result.length) {
            if (l < leftLength && (r >= rightLength || leftSorted[l] <= rightSorted[r])) {
                result[i] = leftSorted[l];
                l++;
            } else {
                if (l < leftLength) {
                    inversionCount += (leftLength - l);
                }
                result[i] = rightSorted[r];
                r++;
            }
            i++;
        }
        return result;
    }

    private long getInversionCount() {
        return inversionCount;
    }

    private long squareCalc(int[] array) {
        long result = 0;
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] > array[j]) {
                    result++;
                }
            }
        }
        return result;
    }
}
